/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MUDCONTAINER_H
#define MUDCONTAINER_H

#include "MudObject.h"
#include "ItemContainer.h"
#include "MudOpenable.h"
#include "MudLockable.h"

namespace Chronos {

class MudItem;
class MudKey;
class MudPlayer;

class MudContainer : public MudObject, public ItemContainer {
public:
    MudContainer(const std::string& name_, const std::string& descr_);

    virtual void accept(CmdVisitor& v);
    virtual const std::string& getDescription() const;

    virtual bool canAccess(MudPlayer& player);
    virtual void addItem(MudItem* item);
    virtual void removeItem(const MudItem* item);
protected:
    virtual void generateDescription();

    std::string customDescription;
private:
    MudContainer(const MudContainer&);
    MudContainer& operator=(const MudContainer&);
};


class MudOpenableContainer : public MudContainer, public MudOpenable {
public:
    MudOpenableContainer(const std::string& name_, const std::string& descr_, unsigned int closeDelay_);

    virtual void accept(CmdVisitor& v);
    virtual bool canAccess(MudPlayer& player);

	virtual void open(MudPlayer& player);
	virtual void close(MudPlayer& player);
    unsigned int reset();
protected:
    virtual void generateDescription();
    bool canOpen(MudPlayer& player);

	bool changed;
	unsigned int closeDelay;
private:
    MudOpenableContainer(const MudOpenableContainer&);
    MudOpenableContainer& operator=(const MudOpenableContainer&);
};


class MudLockedContainer : public MudOpenableContainer, public MudLockable {
public:
    MudLockedContainer(const std::string& name_, const std::string& descr_, unsigned int closeDelay_);

    virtual void accept(CmdVisitor& v);

	virtual void open(MudPlayer& player);
	virtual void lock(MudPlayer& player, const MudKey& key);
	virtual void unlock(MudPlayer& player, const MudKey& key);

    unsigned int reset();
protected:
    virtual void generateDescription();
private:
    MudLockedContainer(const MudLockedContainer&);
    MudLockedContainer& operator=(const MudLockedContainer&);
};

}

#endif

